/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.ArrayList;
import java.util.HashMap;

/**
 *
 * @author Danang
 */
public class FieldList {
    String token;
    // HashMap<field_type, postinglist nya
    HashMap<Integer,PostingList> postinglist_field;
    
    public FieldList(String token) {
        this.token = token;
        postinglist_field = new HashMap<Integer, PostingList>();
        for (int i=1;i<=5;i++) {
            PostingList t = new PostingList(token);
            postinglist_field.put(i, t);
        }
    }
   
    
    public void addPosition(int messageType, int messageID, ArrayList<Integer> list) {
        ((PostingList)postinglist_field.get(messageType)).addPosition(messageID, list);
    }
    
    public String getAllPostingList() {
        StringBuilder sb = new StringBuilder();
        
        for (int i=1;i<=5;i++) {
            sb.append("@").append(i).append("\n");
            sb.append(((PostingList)postinglist_field.get(i)).getAllPosition());
        }
        
        return sb.toString();
    }
    
    public String getPostingListToString(int type) {
        return ((PostingList)postinglist_field.get(type)).getAllPosition();
    }
    
    public PostingList getPostingList(int type) {
        return postinglist_field.get(type);
    }
    
    public String toOutputFile(int type) {
        PostingList retrieveList = postinglist_field.get(type);
        StringBuilder sb = new StringBuilder();
        
        sb.append(token).append(" FIELD=").append(Message.getFieldName(type))
                .append(" DF=").append(retrieveList.getDF()).append("\n");
        sb.append(retrieveList.toString());
        return sb.toString();
    }
    
    public String toString() {
        return this.getAllPostingList();
    }
    
    public String getToken() {
        return this.token;
    }
    
}
